package com.blog.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.jdbc.core.RowMapper;

import com.blog.domain.Menu;


@Repository("menuDAO")
public class MenuDao extends BlogJdbcDaoSupport {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List<Menu> getTreeQuery() {
		String sql = "select id,name,parent_id,sequence_no,res_level,url,show_on_menu,descn from menu";

		List<Menu> menu = this.getJdbcTemplate().query(sql, new RowMapper() {
			public Object mapRow(ResultSet rs, int arg1) throws SQLException {
				Menu bean = new Menu();
				bean.setId(rs.getLong("id"));
				bean.setResourceName(rs.getString("name"));
				bean.setParentId(rs.getLong("parent_id"));
				bean.setSequenceNo(rs.getInt("sequence_no"));
				bean.setResourceLevel(rs.getInt("res_level"));
				bean.setResourceUrl((rs.getString("url")));
				bean.setShowOnMenu(rs.getString("show_on_menu").equals("Y") ? true
						: false);
				bean.setDescn(rs.getString("descn"));
				return bean;
			}
		});
		return menu;
	}

	
}
